<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: cc
  Date: 2017/12/27
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理系统登录</title>
    <script type="text/javascript" src="../../../js/jquery.min.js"></script>
    <script type="text/javascript">
        var flag=false;
        function changecode() {
            var showImg = document.getElementById("capture");
            showImg.src = "/makeCode?id="+Math.random();
            $("#message").html("")
        }

        function checkCode() {
           var code = document.getElementById("inputcapture").value;
           $.ajax({
               url:"/checkcode",
               type:"POST",
               dateType:"json",
               contentType:"application/json;charset=utf-8",
               data:JSON.stringify({'code':code}),
               success:function (data) {
                   if (data.sta==='ok'){
                       flag=true
                   }else if(data.sta==='no'){
                       $("#message").html("验证码错误")
                   }
               },
           });
        }
        function onClickdo() {
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            var code = document.getElementById("inputcapture").value;
            if (username == '' || password == '' || code == '') {
                alert("请输入相关信息")
                return
            }
            $.ajax({
                url: "/doBackGroundLogin",
                type: "POST",
                dateType: "json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({'username': username, 'password': password}),
                success: function (data) {
                    if (data.sta == "ok" && flag) {
                        alert("登陆成功")
                        window.location.href="/showIndex"
                    } else {
                        alert("登陆失败，请检查用户名、密码")
                        window.location.reload()
                    }
                }
            });
        }
    </script>
</head>
<body>
<form method="post" action="/doBackGroundLogin">
<table style="margin: 0 auto">
    <tr>
        <td colspan="2">后台登录</td>
    </tr>
    <tr>
        <td>管理账号:</td><td><input type="text" name="username" id="username"></td>
    </tr>
    <tr>
        <td>管理密码:</td><td><input type="password" name="password" id="password"></td>
    </tr>
    <tr>
        <td>验证码:&nbsp;</td>
        <td><input type="text" name="capture" id="inputcapture" onblur="checkCode()">
            <img width="160px" alt="单击刷新" title="单击刷新" height="30px" src="/makeCode" id="capture" onclick="changecode()">
        </td>
    </tr>
    <tr><td><span id="message" style="color: #ff0000; font-size: 12px"></span></td></tr>
    <tr></tr>
        <td><input type="button" value="登录" onclick="onClickdo()"></td>
    </tr>
</table>
</form>
</body>
</html>
